//
//  ViewController.m
//  footBoll
//
//  Created by zhoubaitong on 2017/9/29.
//  Copyright © 2017年 cckv. All rights reserved.
//

#import "ViewController.h"

#import "baseView.h"

#import "bollView0.h"
#import "bollView1.h"
#import "bollView2.h"
#import "bollView3.h"
#import "bollView4.h"
#import "bollView5.h"
#import "bollView6.h"

#import "gameTipView.h"
#import "UIView+extension.h"

#import "FlowFlower.h"
#import "UIImage+Extension.h"

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]


@interface ViewController ()<UICollisionBehaviorDelegate,UIDynamicAnimatorDelegate,gameTipViewDelegate,boolViewDelegate>

#define kScreenW [UIScreen mainScreen].bounds.size.width
#define kScreenH [UIScreen mainScreen].bounds.size.height

@property (strong, nonatomic) gameTipView *tipV;
@property (strong, nonatomic) UIButton *coverView;
@property (strong, nonatomic) baseView *currentV;
@property (strong,nonatomic)FlowFlower *flowFlower;

@property (assign,nonatomic)BOOL win;

@end

@implementation ViewController
//是否可以旋转

- (BOOL)shouldAutorotate

{
    
    return YES;
    
}
//支持的方向

-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    
    return UIInterfaceOrientationMaskLandscape;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    switch (self.index) {
        case 0:
        {
            bollView0 *v1 = [[bollView0 alloc]init];
            v1.delegate = self;
            self.currentV = v1;
            v1.index = self.index;
            self.view = v1;
            
        }
            break;
        case 1:
        {
            bollView1 *v1 = [[bollView1 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
            
        }
            break;
        case 2:
        {
            bollView3 *v1 = [[bollView3 alloc]init];
            v1.delegate = self;
            self.currentV = v1;
            v1.index = self.index;
            self.view = v1;
        }
            break;
        case 3:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
        case 4:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
        case 5:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
        case 6:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
        case 7:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
        case 8:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
        case 9:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
        case 10:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
        case 11:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
        case 12:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
            
        default:
            break;
    }
}
-(void)gameOver
{
    self.coverView = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:self.coverView];
    self.coverView.frame = self.view.bounds;
    self.coverView.backgroundColor = [UIColor blackColor];
    self.coverView.alpha = 0.5;
//            [self.coverView addTarget:self action:@selector(hideTip) forControlEvents:UIControlEventTouchUpInside];
    
    gameTipView *tipV = [gameTipView vieFromXib];
    self.tipV = tipV;
    tipV.win = self.win;
    tipV.delegate = self;
    [self.view addSubview:tipV];
    tipV.size = CGSizeMake(445, 270);
    tipV.center = self.view.center;

}
-(void)winThisGame
{
    self.win = YES;
    
    // 显示恭喜的特效
    [self FlyColorImage];
    
    __block UILabel *label = [[UILabel alloc]init];
    label.text = NSLocalizedString(@"恭喜你,进球成功", nil);
    label.textColor = [UIColor greenColor];
//    label.backgroundColor = [UIColor whiteColor];
    label.layer.masksToBounds = YES;
    label.layer.cornerRadius = 8;
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont fontWithName:@"AmericanTypewriter-Bold" size:40];
    label.x = 0;
    label.centerY = self.view.centerY;
    label.height = 50;
    label.width = kScreenW;
    [self.view addSubview:label];
    
    // 特效消失-显示操作
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [label removeFromSuperview];
        label = nil;
        
        [_flowFlower endFlyFlower];
        
        [self gameOver];
        
    });
    
}
- (void)hideTip
{
    [self.coverView removeFromSuperview];
    self.coverView = nil;
    [self.tipV removeFromSuperview];
    self.tipV = nil;
}
-(void)clickBackButton
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

#pragma mark - tipDelegate
-(void)chooseLevel
{
    [self dismissViewControllerAnimated:NO completion:^{
        [[NSNotificationCenter defaultCenter] postNotificationName:@"chooseLevel" object:nil];
    }];
}
-(void)clickReStart
{
    [self hideTip];
    [self.currentV reload];
}

-(void)nextGame
{
    self.index += 1;
    
    self.win = NO;
    
    switch (self.index) {
        case 0:
        {
            bollView0 *v1 = [[bollView0 alloc]init];
            v1.delegate = self;
            self.currentV = v1;
            v1.index = self.index;
            self.view = v1;
            
        }
            break;
        case 1:
        {
            bollView1 *v1 = [[bollView1 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
            
        }
            break;
        case 2:
        {
            bollView3 *v1 = [[bollView3 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
        case 3:
        {
            [SVProgressHUD showErrorWithStatus:NSLocalizedString(@"敬请期待", nil)];
            [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
            [SVProgressHUD dismissWithDelay:1];
//            bollView2 *v1 = [[bollView2 alloc]init];
//            v1.delegate = self;
//            self.view = v1;
//            self.currentV = v1;
//            v1.index = self.index;
        }
            break;
        case 4:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
        case 5:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
        case 6:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
        case 7:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
        case 8:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
        case 9:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
        case 10:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
        case 11:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
        case 12:
        {
            bollView2 *v1 = [[bollView2 alloc]init];
            v1.delegate = self;
            self.view = v1;
            self.currentV = v1;
            v1.index = self.index;
        }
            break;
            
        default:
            break;
    }
    
}

#pragma mark - 鲜花
-(void)FlyColorImage{
    
    UIImage *image1 = [UIImage imageWithColor:UIColorFromRGB(0xFFBF00)];
    UIImage *image2 = [UIImage imageWithColor:UIColorFromRGB(0x038AE6)];
    UIImage *image3 = [UIImage imageWithColor:UIColorFromRGB(0x73D0F5)];
    UIImage *image4 = [UIImage imageWithColor:UIColorFromRGB(0xD93600)];
    UIImage *image5 = [UIImage imageWithColor:UIColorFromRGB(0xFFFF00)];
    UIImage *image6 = [UIImage imageWithColor:UIColorFromRGB(0x3DB59)];
    
    _flowFlower = [FlowFlower flowerFLow:@[image1,image2,image3,image4,image5,image6]];
    [_flowFlower startFlyFlowerOnView:self.view];
}
@end
